<?php
/**
 * @author li ming
 * @date 2021-10-12
 */
namespace Modules\User\Http\Controllers\Api;

use Illuminate\Http\Request;
use Modules\User\Entities\User;
use Modules\User\Services\Api\UserServices;
use Tymon\JWTAuth\Facades\JWTAuth;

class LocalController extends ApiBaseController
{

    /**
     * @var UserServices
     * @author tan bing
     */
    private $request;

    /**
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    /**
     * 本地测试登录，上线要删除
     * @author li ming
     */
    public function login()
    {
        $data = $this->request->input();
        $user_id = $data["user_id"] ?? 0;
        $user = User::where("id", $user_id)->first();
        if(!$user) return $this->failed("账号或者密码错误");
        $token = JWTAuth::fromUser($user);
        return $this->success(compact("user","token"));
    }
}